package com.sky.service.user.impl;

import com.alibaba.fastjson.JSON;
import com.hxc.pay.wx.service.PaySuccessService;
import com.sky.mapper.user.OrderMapper;
import com.sky.pojo.Orders;
import com.sky.webscoket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Service
public class PaySuccessServiceImpl implements PaySuccessService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private WebSocketServer webSocketServer;

    @Override
    public void success(String outTradeNo) {
        //修改订单状态
        Orders orders = new Orders();
        orders.setPayStatus(Orders.PAID);
        orders.setStatus(Orders.TO_BE_CONFIRMED);
        orders.setCheckoutTime(LocalDateTime.now());
        orders.setNumber(outTradeNo);
        System.out.println("----支付成功-----修改订单状态");
        orderMapper.updatePaySuccess(orders);
        //来单
        Map<String,Object> map=new HashMap<>();
        map.put("type",1);
        map.put("orderId",orders.getNumber());
        map.put("concent","您有新订单,请及时处理");
        webSocketServer.sendAll(JSON.toJSONString(map));
    }
}
